//
//   Copyright (c) 2009 Bálint Jánvári
//       www.programmaticmagic.com
//  
//  Permission is hereby granted, free of charge, to any person
//  obtaining a copy of this software and associated documentation
//  files (the "Software"), to deal in the Software without
//  restriction, including without limitation the rights to use,
//  copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the
//  Software is furnished to do so, subject to the following
//  conditions:
//
//  The above copyright notice and this permission notice shall be
//  included in all copies or substantial portions of the Software.
//
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
//  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
//  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
//  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
//  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
//  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
//  OTHER DEALINGS IN THE SOFTWARE.
 
//
//  OMGeometry.h
//  ObjectiveMagic
//

/*
 OMGeometry offers shortcut functions for common
 operations with CGPoint, CGRect and CGSize values
 */

#import <CoreGraphics/CoreGraphics.h>
#import <math.h>

/*
 Converts an angle in degrees to an angle in radians
 */
CG_INLINE CGFloat OMDegreeToRadian(CGFloat degree)
{
	return degree / 180.0f * M_PI;
}

/*
 Converts an angle in radians to an angle in degrees
 */
CG_INLINE CGFloat OMRadianToDegree(CGFloat radian)
{
	return radian * 180.0f / M_PI;
}

/*
 Returns the center of a rectangle
 */
CG_INLINE CGPoint CGRectCenter(CGRect r)
{
	return CGPointMake(r.origin.x + r.size.width / 2, r.origin.y + r.size.height / 2);
}

/*
 Creates a rectangle using its center and its width and height
 */
CG_INLINE CGRect CGRectMakeWithCenter(CGPoint center, CGFloat width, CGFloat height)
{
	return CGRectMake(center.x - width / 2, center.y - height / 2, width, height);
}

/*
 Returns the point halfway between two points
 */
CG_INLINE CGPoint CGPointInTheMiddle(CGPoint pt1, CGPoint pt2)
{
	return CGPointMake((pt1.x + pt2.x) / 2, (pt1.y + pt2.y) / 2);
}

/*
 Returns the distance between two points
 */
CG_INLINE CGFloat CGPointDistance(CGPoint pt1, CGPoint pt2)
{
	return sqrtf((pt2.x - pt1.x) * (pt2.x - pt1.x) + (pt2.y - pt1.y) * (pt2.y - pt1.y));
}

/*
 Creates a bounds rectangle from a CGSize
 */
CG_INLINE CGRect CGRectFromSize(CGSize size)
{
	return CGRectMake(0, 0, size.width, size.height);
}